package com.jia.videos.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jia.videos.entity.LittleVideo;
import com.jia.videos.mapper.LittleVideoMapper;
import com.jia.videos.service.LittleVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dujiajia
 * @since 2020-12-23
 */
@Service
public class LittleVideoServiceImpl extends ServiceImpl<LittleVideoMapper, LittleVideo> implements LittleVideoService {


    @Override
    public Map<String,Object> getPageList(Integer pageNum, Integer pageSize) {
        QueryWrapper<LittleVideo> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_time").orderByDesc("sort");

        Page<LittleVideo> page1 = new Page<>(pageNum,pageSize);
        IPage<LittleVideo> littleVideoIPage = baseMapper.selectPage(page1, wrapper);
        List<LittleVideo> records = littleVideoIPage.getRecords();
        long total = littleVideoIPage.getTotal();

        Map<String, Object> map = new HashMap<>();
        map.put("records",records);
        map.put("total",total);
        return map;
    }
}
